Interop Forms Toolkit
How To Debug a Hybrid Application

Debugging Visual Basic 6.0 Code

Debugging Visual Basic 6.0 code in a Hybrid application is no different than debugging any other Visual Basic 6.0 project.  Press F5 to run, set breakpoints, and debug as you normally would.  There are two different methods for stepping into your .NET  — by attaching to a process from Visual Studio .NET, or by setting a Start Action in Visual Studio .NET.

 

Debugging with Attach to Process

You will not be able to step into .NET code, however, without performing a few additional steps.  Follow these steps to debug your .NET code:

  1. Load your .NET project in Visual Studio .NET
  2. Build the .NET project if it has not already been built
  3. Load your Visual Basic 6.0 code in the Visual Basic 6.0 IDE
  4. Run your application by pressing F5 in the Visual Basic 6.0 IDE (Note: You must do this once before attaching the .NET debugger to properly load the .NET code)
  5. In Visual Studio .NET, select Attach to Process... from the Tools menu
  6. In the dialog that appears, select the Visual Basic 6.0.exe process (Note: because the Visual Basic 6.0 code runs within the Visual Basic 6.0 IDE, you must select this process to debug)

 

You only need to repeat the steps above after rebuilding .NET code.  The Visual Basic 6.0 IDE must be closed when rebuilding. After completing these steps, press F5 in the Visual Basic 6.0 IDE to run, set breakpoints, and debug as you normally would. Remember that since the Visual Basic 6.0 IDE process is being debugged, you will not be able to navigate in the Visual Basic 6.0 code while stopped on a breakpoint. 

 

Debugging with Start external program

Instead of manually attaching to the process every time, you can configure your Visual Studio .NET project to automatically launch Visual Basic 6.0.  To debug in Visual Studio .NET, you can set the debugger to start an external program, and pass it the path to the Visual Basic 6.0 application. When you run the project in Visual Studio .NET, your Visual Basic 6.0 project will be launched; you can then set breakpoints in Visual Basic 6.0 and step into the .NET code.

Note : Both Interop UserControls and InteropForms cannot be built or debugged in Visual Studio .NET while an instance is open in Visual Basic 6.0.  

Note :  If any changes are made in Visual Basic 6.0 during debugging you must explicitly save your changes. When you stop debugging in Visual Studio .NET, Visual Basic 6.0 will be terminated without prompting to save changes.

1.     Close the Visual Basic 6.0 IDE.

2.     In Visual Studio .NET, in Solution Explorer right-click the My Project node and click Open.

3.     In the Project Explorer, select the Debug tab, and under Start Action select Start external program.

4.     In the text box, type vb6.exe. Note that if vb6.exe is not defined as an environment variable you may have to browse to your Visual Basic 6.0 directory in order to include the path.

5.     In the Command line arguments field, type the full path to your Visual Basic 6.0 project, i.e. "C:\Program Files\My Projects\InteropProject.vbp". Note that the path and filename must be enclosed in quotes.

6.     In Visual Studio .NET, set breakpoints as needed and then press F5. The project will run and Visual Basic 6.0 will be launched and your project loaded.

7.     In Visual Basic 6.0, set breakpoints as needed and then press F5. As the application executes and a breakpoint is hit, you can press F8 to step into the Visual Studio .NET code. If you make changes in Visual Basic 6.0, you must save your changes before you stop debugging in Visual Studio .NET or your changes will be lost.

Static Memory

When you run an application in the Visual Basic 6.0 IDE, it does not launch in a new process.  This has the negative side effect of not clearing out shared variables (static memory) between runs.